package com.ruoyi.st.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.st.domain.StMenuCat;
import com.ruoyi.st.service.IStMenuCatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单分类Controller
 * 
 * @author ruoyi
 * @date 2024-11-06
 */
@RestController
@RequestMapping("/st/cat")
public class StMenuCatController extends BaseController
{
    @Autowired
    private IStMenuCatService stMenuCatService;

    /**
     * 查询菜单分类列表
     */
    @PreAuthorize("@ss.hasPermi('st:cat:list')")
    @GetMapping("/list")
    public TableDataInfo list(StMenuCat stMenuCat)
    {
        startPage();
        List<StMenuCat> list = stMenuCatService.selectStMenuCatList(stMenuCat);
        return getDataTable(list);
    }

    /**
     * 导出菜单分类列表
     */
    @PreAuthorize("@ss.hasPermi('st:cat:export')")
    @Log(title = "菜单分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StMenuCat stMenuCat)
    {
        List<StMenuCat> list = stMenuCatService.selectStMenuCatList(stMenuCat);
        ExcelUtil<StMenuCat> util = new ExcelUtil<StMenuCat>(StMenuCat.class);
        util.exportExcel(response, list, "菜单分类数据");
    }

    /**
     * 获取菜单分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('st:cat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stMenuCatService.selectStMenuCatById(id));
    }

    /**
     * 新增菜单分类
     */
    @PreAuthorize("@ss.hasPermi('st:cat:add')")
    @Log(title = "菜单分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StMenuCat stMenuCat)
    {
        return toAjax(stMenuCatService.insertStMenuCat(stMenuCat));
    }

    /**
     * 修改菜单分类
     */
    @PreAuthorize("@ss.hasPermi('st:cat:edit')")
    @Log(title = "菜单分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StMenuCat stMenuCat)
    {
        return toAjax(stMenuCatService.updateStMenuCat(stMenuCat));
    }

    /**
     * 删除菜单分类
     */
    @PreAuthorize("@ss.hasPermi('st:cat:remove')")
    @Log(title = "菜单分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stMenuCatService.deleteStMenuCatByIds(ids));
    }
}
